using System;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace ProjectMyFarmAndShe
{
    public partial class MessagePanel : ViewController
    {
        public static MessagePanel Default;

        private void Awake()
        {
            Default = this;

            MessageItemTemplate.Hide();
        }

        void Start()
        {
            // Code Here
        }

        /// <summary>
        /// 添加消息
        /// </summary>
        /// <param name="content">消息内容</param>
        public void AddMessage(string content)
        {
            MessageItemTemplate.InstantiateWithParent(Root)
                .Self(self =>
                {
                    self.MessageText.text = content;

                    ActionKit.Delay(2f, () =>
                        {
                            self.DestroyGameObjGracefully();
                            
                        })
                        .Start(self);
                })
                .Show();
        }

        private void OnDestroy()
        {
            Default = null;
        }
    }
}